package com.game.framwork.gamesupport;

import java.util.LinkedList;

import android.graphics.Rect;

import com.game.object.JObject;

public class QuadTreeNode {

	public int nodeLevel;
	public int upperLeftX;
	public int upperLeftY;
	public int width;
	public int height;

	LinkedList<JObject> listObject;

	public QuadTreeNode[] pSubNode;
	public QuadTreeNode pParentNode;

	public QuadTreeNode(QuadTreeNode pParentNode, int upperLeftX,
			int upperLeftY, int width, int height) {
		this.upperLeftX = upperLeftX;
		this.upperLeftY = upperLeftY;
		this.width = width;
		this.height = height;

		if (pParentNode == null) {
			this.nodeLevel = 1;
			this.pParentNode = null;
		} else {
			this.nodeLevel = pParentNode.nodeLevel + 1;
			this.pParentNode = pParentNode;
		}
		listObject = new LinkedList<JObject>();
		pSubNode = null;
	}

	public void addObject(JObject pObject) {
		listObject.add(pObject);
	}

	public boolean removeObject(JObject pOjbect) {
		JObject temptObject = pOjbect;
		int size = listObject.size();
		for (int i = 0; i < size; i++) {
			if (listObject.get(i) == temptObject) {
				listObject.remove(i);
				return true;
			}
		}
		return false;
	}

	public LinkedList<JObject> getObject(LinkedList<JObject> pListObject) {
		LinkedList<JObject> temptListObject = pListObject;
		int size = listObject.size();
		if (size > 0) {
			for (int i = 0; i < size; i++) {
				temptListObject.add(listObject.get(i));
			}
		}
		return temptListObject;
	}

	public Rect getSize() {
		Rect recBound = new Rect(upperLeftX, upperLeftY, upperLeftX + width,
				upperLeftY + height);

		return recBound;
	}

	public void release() {
		this.listObject.clear();
	}
}
